const path = require('path')

const CssLoader = (importLoaders) => {
  return {
    loader: 'css-loader',
    options: {
      importLoaders: importLoaders,
      esModule: false
    }
  }
}

module.exports = {
  entry: './src/index.js',
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, 'dist')
    // 设置asset资源【全局】
    // assetModuleFilename: 'img/[name].[hash:4][ext]'
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader', 
          CssLoader(1), 
          'postcss-loader'
        ]
      }, 
      {
        test: /\.less$/,
        use: [
          'style-loader', 
          CssLoader(1),
          'postcss-loader', 
          'less-loader'
        ]
      }, 
      // {
      //   test: /\.(png|svg|gif|jpe?g)$/,
      //   type: 'asset/resource',
      //   // 当前类型的设置
      //   generator: {
      //     filename: 'img/[name].[hash:4][ext]'
      //   }
      // }

      // {
      //   test: /\.(png|svg|gif|jpe?g)$/,
      //   type: 'asset/inline'
      // }
      {
        test: /\.(png|svg|gif|jpe?g)$/,
        type: 'asset',
        generator: {
          filename: 'img/[name].[hash:4][ext]'
        },
        parser: {
          dataUrlCondition: {
            maxSize: 4 * 1024
          }
        }
      }
    ]
  }
}